/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AUDIO_ENDPOINT_SINK_ADAPTER_H
#define AUDIO_ENDPOINT_SINK_ADAPTER_H

#include <unordered_map>
#include <string>
#include <list>
#include <mutex>
#include <memory>

#include "audio_endpoint.h"

namespace OHOS {
namespace AudioStandard {
class AudioEndpointSinkAdapter {
private:
    using EndpointName = std::string;
    std::unordered_map<uint32_t, std::list<std::pair<EndpointName, AudioEndpoint::EndpointStatus>>> operationMap;
    std::mutex checkerOperationMapMutex_;
public:
    // init of static local variables is thread-safe.
    static std::shared_ptr<AudioEndpointSinkAdapter> GetInstance()
    {
        static std::shared_ptr<AudioEndpointSinkAdapter> checkerInstance =
            std::make_shared<AudioEndpointSinkAdapter>();
        return checkerInstance;
    }

    bool IsOtherEndpointRunning(const uint32_t fastRenderid, const EndpointName &Key);

    void AddOperation(const uint32_t fastRenderid, const EndpointName &Key, AudioEndpoint::EndpointStatus status);

    void RemoveOperation(const uint32_t fastRenderid);

    void UpdateStatus(const uint32_t fastRenderid, const EndpointName &Key,
        const AudioEndpoint::EndpointStatus &newStatus);
    
    AudioEndpointSinkAdapter() = default;
    ~AudioEndpointSinkAdapter() = default;
};
}
}
#endif
